<template>
  <view class="refund-info">
    <view class="content">
      <view class="title">{{ $t("order.description") }}</view>
      <view class="text">
        <textarea
          style="margin-top: 24rpx; width: 100%"
          v-model="desc"
          :placeholder="$t('order.moreDes')"
          placeholder-style="color:#ccc;font-size:24rpx;"
        />
      </view>
      <view class="picList">
        <view class="picItem" v-for="(item, index) in pic_list" :key="index">
          <view class="close" @click="delPic(index)">
            <text class="iconfont icon-close"></text>
          </view>
          <image :src="item"></image>
        </view>
        <view class="picItem" @click="chooseImage" v-if="pic_list.length < 6">
          <text class="iconfont icon-camera"></text>
          <text>{{ $t("order.addPic") }}</text>
        </view>
      </view>
    </view>
    <view class="submit-section">
      <view class="submit-btn" @click="submitRefund">{{
        $t("home.submit")
      }}</view>
    </view>
  </view>
</template>

<script>
import http from "@/common/http.js";
export default {
  data() {
    return {
      pic_list: [],
      desc: "",
      type: 1, // 1退货退款 2换货
      showSelect: false,
      refundTypeList: [
        {
          name: this.$t("order.refund"),
          value: 1
        },
        {
          name: this.$t("order.exchangeGoods"),
          value: 2
        }
      ]
    };
  },
  props: {
    goods: {
      type: Object,
      default: function () {
        return null;
      }
    }
  },
  methods: {
    // 提交售后详情表单
    submitRefund() {
      var data = {
        type: this.type,
        desc: this.desc,
        pic_list: this.pic_list
      };
      this.$emit("submitRefund", data);
    },

    chooseImage() {
      this.$utils.uploadImage(6 - this.pic_list.length, (res) => {
        this.pic_list.push(res);
      });
    },

    // 删除选中的图片
    delPic(pic_index) {
      this.pic_list.splice(pic_index, 1);
    }

    // 选择售后类型
    // chooseRefundType(res) {
    //   this.type = res[0].value;
    // },
  }
};
</script>

<style lang="scss" scoped>
.refund-info {
  .refund-type {
    display: flex;
    align-items: center;
    justify-content: space-between;

    .select-label {
      font-size: 28rpx;
      font-weight: 400;
      color: #8c8c8c;
      line-height: 32rpx;
    }

    .select-box {
      display: flex;
      justify-content: flex-end;
      align-items: center;

      text {
        font-size: 28rpx;
        font-family: PingFang SC;
        font-weight: 500;
        color: #262626;
        line-height: 32rpx;
        margin-right: 10rpx;
      }

      image {
        width: 10rpx;
        height: 20rpx;
      }
    }
  }

  .hold-line {
    width: 630rpx;
    height: 1rpx;
    background: #f2f2f2;
    margin: 40rpx auto 30rpx;
  }

  .refund-desc {
    width: 630rpx;
    min-height: 148rpx;
    background: #f2f2f2;
    border-radius: 10rpx;
    margin: 0 auto;
    padding: 25rpx;

    textarea {
      width: 100%;
      height: 100rpx;
    }
  }

  .refund-imgs {
    width: 630rpx;
    display: flex;
    flex-wrap: wrap;
    margin-top: 30rpx;

    .upload-img-item {
      width: 140rpx;
      height: 140rpx;
      background: #ffffff;
      border: 2rpx solid #f2f2f2;
      border-radius: 10rpx;
      margin-right: 23rpx;
      display: flex;
      justify-content: center;
      align-items: center;
      flex-direction: column;
      position: relative;

      view {
        font-size: 24rpx;
        font-family: PingFang SC;
        font-weight: 400;
        color: #8c8c8c;
        line-height: 32rpx;
        margin-top: 16rpx;
        position: relative;
      }

      .item-image {
        width: 100%;
      }

      .close-icon {
        width: 30rpx;
        height: 30rpx;
        position: absolute;
        right: -15rpx;
        top: -15rpx;
        z-index: 11;
      }
    }

    .upload-img-item:last-child {
      margin-right: 0;
    }
  }
}
.content {
  padding: 36rpx;
  background-color: #fff;
  margin-top: 20rpx;
  .title {
    font-size: 30rpx;
    color: #262626;
    font-weight: 600;
    font-family: PingFang SC;
  }
  .picList {
    display: flex;
    flex-wrap: wrap;
    .picItem {
      margin-top: 20rpx;
      position: relative;
      background-color: #f6f6f6;
      height: 210rpx;
      width: 210rpx;
      margin-right: 24rpx;
      border-radius: 16rpx;
      font-size: 24rpx;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      overflow: hidden;
      color: #8c8c8c;
      overflow: hidden;
      image {
        width: 100%;
        height: 100%;
      }
      .iconfont {
        font-size: 80rpx;
        color: #262626;
      }
      .close {
        z-index: 100;
        position: absolute;
        width: 45rpx;
        height: 45rpx;
        right: 0;
        top: 0;
        border-radius: 0 16rpx 0 40rpx;
        display: flex;
        align-items: center;
        justify-content: center;
        background-color: #acacac;
        .iconfont {
          font-size: 28rpx;
          color: #fff;
        }
      }
    }
    .picItem:nth-child(3n) {
      margin-right: 0;
    }
  }
}
.submit-section {
  width: 100%;
  margin-top: 40rpx;
  display: flex;
  justify-content: center;
  align-items: center;
  .submit-btn {
    width: 678rpx;
    height: 76rpx;
    background: linear-gradient(90deg, #ff4e18, #f32524);
    border-radius: 38rpx;
    text-align: center;
    line-height: 76rpx;
    font-size: 30rpx;
    font-family: PingFang SC;
    font-weight: 500;
    color: #ffffff;
  }
}
</style>
